import pyglet
import math

class Collideable(pyglet.sprite.Sprite):
    def __init__(self, img, x=0, y=0, blend_src=770, blend_dest=771, 
                 batch=None, group=None, usage='dynamic', world=None):
        super(Collideable, self).__init__(img, x=x, y=y, blend_src=blend_src, 
                                          blend_dest=blend_dest, batch=batch, 
                                          group=group, usage=usage)

class StaticObject(Collideable):
    def __init__(self, img, x=0, y=0, blend_src=770, blend_dest=771, 
                 group=None, usage='dynamic', world=None):
        super(StaticObject, self).__init__(img, x=x, y=y, blend_src=blend_src, 
                                           blend_dest=blend_dest, group=group, 
                                           usage=usage, batch=world.batch_static,
                                           world=world)

class PhysicsObject(Collideable):
    def __init__(self, img, x=0, y=0, vel_x=0, vel_y=0, rot=0, blend_src=770, 
                 blend_dest=771, group=None, usage='dynamic', world=None):
        super(PhysicsObject, self).__init__(img, x=x, y=y, blend_src=blend_src, 
                                            blend_dest=blend_dest, group=group, 
                                            usage=usage, batch=world.batch_physics,
                                            world=world)
        
        self.rotation = rot
        
        self.vel_x = vel_x
        self.vel_y = vel_y
        
        # Set gravity to global values.
        self.g = world.g

    def update(self, dt):
        self.vel_x -= math.sin(self.rotation * math.pi / 180) * self.g * dt
        self.vel_y -= math.cos(self.rotation * math.pi / 180) * self.g * dt

        self.x += self.vel_x * dt
        self.y += self.vel_y * dt
